//
//  MainTabBarController.swift
//  IFXY
//
//  Created by LiuXing on 2016/12/29.
//  Copyright © 2016年 IFly. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        addChildViewControllers()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    func addChildViewControllers() {
        addChildViewController(childController: HomeViewController(), title:"News" , imageName: "tabbar-shop")
        addChildViewController(childController: ShopTableViewController(), title: "Shop", imageName: "tabbar-category")
        addChildViewController(childController: SupportTableViewController(), title:"SUPPORT" , imageName: "tabbar-mart")
        addChildViewController(childController: ProfileViewController(), title: "ACCOUNT", imageName: "tabbar-my")
    }
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "-selected")
        let nav = MainNavViewController()
        nav.addChildViewController(childController)
        addChildViewController(nav)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension MainTabBarController {

    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        if item.title == "我的" {
             NotificationCenter.default.post(name: NSNotification.Name(rawValue:"updateLicenseDayNoti"), object: self, userInfo: nil)
        }
    }
}
